<?php

ini_set('xdebug.var_display_max_data', '2048');
ini_set('xdebug.var_display_max_depth', '7');

include '../core/core.php';

CCore::Using('base.followers.logger');
CCore::Using('logger.inline');
CCore::Using('logger.file');
CCore::Using('net.imap');
CCore::Using('mime.message');
CCore::Using('mime.callbacks.test');

$oImapConfig = new CCoreNetImapConfig('u-server', 143, 'test@localhost', 'p12345', 5, 5);
$oImap = new CCoreNetImap($oImapConfig);

$oLogger1 = new CCoreLoggerInline("\n", true);
$oLogger2 = new CCoreLoggerFile('c:/php.core.log.txt');
$oFollower1 = new CCoreBaseFollowersLogger($oLogger1);
$oFollower2 = new CCoreBaseFollowersLogger($oLogger2);

//$oImap->AddFollower($oFollower1);
//$oImap->AddFollower($oFollower2);

if ($oImap->ConnectAndLogin())
{
	$oImap->FolderSelect('INBOX');

	$test = new test1();
	
	$aInputFetchItems = array();
	CCoreNetImapFetchItem::AddToArray($aInputFetchItems, ECoreNetImapFetch::FLAGS);
	CCoreNetImapFetchItem::AddToArray($aInputFetchItems, ECoreNetImapFetch::BODY.'[]', array(&$test, 'DoIt'));

	$oImap->Fetch($aInputFetchItems, '1', false);
	$oImap->LogoutAndDisconnect();
}

class test1
{
	function DoIt($rStream, $sLiteralAtomUpperCase)
	{
		if (ECoreNetImapFetch::BODY.'[]' === $sLiteralAtomUpperCase)
		{
			//echo stream_get_contents($rStream);
			/**/

			$oCallbackClass = new CCoreMimeCallbacksTest();
			//$oCallbackClass = null;
			
			$oMessage = new CCoreMimeMessage();
			$oMessage->ParseFromStream($rStream, $oCallbackClass);
			//var_dump($oMessage);
			//$oMessage->SubParts->GetByIndex(1)->PassthruBody();
			//$oMessage->SubParts->GetByIndex(1)->PassthruBinaryBody(true);
			return $oMessage;
			/* */
		}
		
		return '';
	}
}

